package com.shop.zkmall.app.consumer;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.shop.zkmall.app.common.RocketConstants;
import com.shop.zkmall.app.domain.req.SendGiftReq;
import com.shop.zkmall.app.domain.req.SendReq;
import com.shop.zkmall.app.service.a.ICereBuyerGiftRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 用户足迹处理消费者
 *
 * @author heishe404
 * @date 2024/11/15 16:53
 **/
@Slf4j
@Component
@RocketMQMessageListener(topic = RocketConstants.SEND_GIFT_TOPIC, consumerGroup = "live-consumer")
public class SendGiftRocketConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private ICereBuyerGiftRecordService cereBuyerGiftRecordService;

    @Override
    public void onMessage(MessageExt ext) {
        String body = new String(ext.getBody());
        SendReq bean = JSONUtil.toBean(body, SendReq.class);
        cereBuyerGiftRecordService.sendGift(bean.getUserId(),bean.getAnchorId(),bean.getSendGiftReq());
        log.info("【消费者】用户送礼物处理消息：消息体 => {}, tag => {}", body, ext.getTags());
    }
}
